<?php
/**
 * Trainingofferadmin_Data_Trainingofferupdate
 *
 * @author Adrian Stolarski
 */
class Trainingofferadmin_Data_Trainingofferupdate implements Trainingofferadmin_Data_Mainable, 
        Trainingofferadmin_Data_Preparable, Trainingofferadmin_Data_Redirectable{
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    
    /**
     *
     * @var type $database_query
     * database query handler
     */
    public $database_query;
    
    /**
     *
     * @var type $redirect_action
     * redirect action
     */
    public $redirect_action;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * insert new offer
     * @param array $variables
     */
    public function main(array $variables = null) {
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        $this->prepare_query($variables);
        $this->database->prepare($this->database_query);
        $this->database->query();
        $this->database->dataOperations();
        $this->redirect_action($variables);
    }
    
    /**
     * prepare_query()
     * prepare database query
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        $this->database_query = "UPDATE "
                . "training_offer"
                . " SET "
                . "page_main_category_id="
                .$variables['page_main_category_id'].
                ", "
                . "page_sub_category_id="
                .$variables['page_sub_category_id'].
                ", "
                . "active_offer_id="
                .$variables['active_offer_id'].
                ", "
                . "training_title='"
                .$variables['training_title'].
                "', "
                . "training_keywords='"
                .$variables['training_keywords'].
                "', "
                . "training_short_description='"
                .$variables['training_short_description'].
                "', "
                . "training_long_description='"
                .$variables['training_long_description '].
                "', "
                . "training_date='"
                .$variables['training_date'].
                "', "
                . "training_location='"
                .$variables['training_location'].
                "', "
                . "training_duration="
                .$variables['training_duration'].
                ", "
                . "number_of_training_days="
                .$variables['number_of_training_days'].
                ", "
                . "all_training_hours="
                .$variables['all_training_hours'].
                ", "
                . "end_of_recrutation='"
                .$variables['end_of_recrutation'].
                ", "
                . "contact_to_company='"
                .$variables['contact_to_company'].
                ", "
                . "contact_about_training='"
                .$variables['contact_about_training'].
                "', "
                . "training_plan='"
                .$variables['training_plan'].
                "'"
                . " WHERE "
                . "id="
                .$variables['id'].
                ";";
    }
    
    /**
     * redirect_action()
     * redirect to offers list
     * @param array $variables
     */
    public function redirect_action(array $variables = null) {
        $this->redirect_action = new Trainingofferadmin_Data_Manageofferslistredirect;
        $this->redirect_action->main($variables);
    }
}
